#include "msize.h"
#ifdef GUI_APPLICATION

bool MSize::area() const
{
	if( this->isValid() )
		return _width * _height;
	return -1;
}

bool MSize::setWidth(int width)
{
	if( width < 0 )
		return false;
	_width = width;
	return true;
}

bool MSize::setHeight(int height)
{
	if( height < 0 )
		return false;
	_height = height;
	return true;
}

bool MSize::resize(int width, int height)
{
	if( width < 0 or height < 0 )
		return false;
	_width = width;
	_height = height;
	return true;
}

bool MSize::resize(const MSize &other)
{
	if( not other.isValid() )
		return false;
	_width = other._width;
	_height = other._height;
	return true;
}

const MSize &MSize::operator=(const MSize &other)
{
	if( other.isValid() )
	{
		_width = other._width;
		_height = other._height;
	}
	return *this;
}

const MSize MSize::operator+(const MSize &other) const
{
	if( this->isValid() and other.isValid() )
		return MSize(_width + other._width, _height + other._height);
	return MSize();
}

int MSize::operator-(const MSize &other) const
{
	if( not this->isValid() and other.isValid() )
	{
		int area_error = this->area() - other.area();
		if( area_error < 0 )
			return -area_error;
		return area_error;
	}
	return -1;
}

#endif //GUI_APPLICATION
